<?php
namespace plugins\dfer_thinkcmf_tools\logic;

use Dfer\Tools\Statics\Common;

class ModelLogic
{
  
    /**
     * 处理富文本内容中的元素。img、iframe、video
     * @param {Object} $value content字段的值
     * @param {Object} $data 所有字段的值
     * @param {Object} $default_poster 默认封面。eg:http://kp.tye3.com/themes/v2/public/assets/images/default_poster.jpg
     **/
    public static function processContent($value,$data,$default_poster = null)
    {
    	$content = cmf_replace_content_file_url(htmlspecialchars_decode($value));        
        $thumbnail=$data['thumbnail'];
    	$poster =  $thumbnail?cmf_get_image_url($thumbnail):$default_poster;
    	
    	if(cmf_is_mobile()) {
    	    $content = str_replace("<img", "<img onclick='imgPreviewFront(this.src)' class='img-fluid' style='max-width:98%;height:auto;'", $content);
    	    $content = str_replace("<iframe", "<iframe style='width:98%;height:auto'", $content);
    	    $content = str_replace("<video", "<video style='width:98%;height:auto' preload", $content);
    	} else{
    	    $content = str_replace("<img", "<img onclick='imgPreviewFront(this.src)' class='img-fluid' style='max-width:95%;height:auto;'", $content);
    	    $content = str_replace("<iframe", "<iframe  style='width:95%;height:auto'", $content);
    	    $content = str_replace("<video", "<video style='width:95%;height:auto' preload", $content);
    	}
        
		// 设置内容里每个视频的封面为各自的OSS截帧图片
		$content=Common::setHtmlVideoCover($content,$poster);
    	return trim($content);
    }
	
	
	
	
	
}